package com.ocm.tourism.core.jdbc.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.ocm.tourism.core.domain.Business;
import com.ocm.tourism.core.domain.FileInfo;
import com.ocm.tourism.core.domain.SaleOff;
import com.ocm.tourism.core.domain.ScheduleTour;

public class TourAgencyAdvRowMapper implements RowMapper<ScheduleTour>{

   public ScheduleTour mapRow(ResultSet resultSet, int rownumber) throws SQLException {
      Business business = new Business();
      business.setId(resultSet.getLong("bus_id"));
      business.setAddress(resultSet.getString("bus_address"));
      business.setDescription(resultSet.getString("bus_desc"));
      business.setFax(resultSet.getString("bus_fax"));
      business.setMobilephone(resultSet.getString("bus_mobile"));
      business.setHomephone(resultSet.getString("bus_homephone"));
      business.setName(resultSet.getString("bus_name"));

      FileInfo avatar = new FileInfo();
      avatar.setId(resultSet.getLong("fi_id"));
      avatar.setAbsolutePath(resultSet.getString("fi_absolutepath"));
      avatar.setExtension(resultSet.getString("fi_extension"));
      avatar.setFileDetail(resultSet.getString("fi_fileDetail"));
      avatar.setMimetypes(resultSet.getString("fi_minetypes"));
      avatar.setName(resultSet.getString("fi_name"));

      business.setAvatar(avatar);

      ScheduleTour scheduleTour = new ScheduleTour();
      scheduleTour.setId(resultSet.getLong("sad_id"));
      scheduleTour.setTitle(resultSet.getString("sad_title"));
      scheduleTour.setTime(resultSet.getString("sad_time"));
      
      FileInfo sadAvatar = new FileInfo();
      sadAvatar.setId(resultSet.getLong("afi_id"));
      sadAvatar.setAbsolutePath(resultSet.getString("afi_absolutepath"));
      sadAvatar.setExtension(resultSet.getString("afi_extension"));
      sadAvatar.setFileDetail(resultSet.getString("afi_fileDetail"));
      sadAvatar.setMimetypes(resultSet.getString("afi_minetypes"));
      sadAvatar.setName(resultSet.getString("afi_name"));

      SaleOff saleOff = new SaleOff();
      saleOff.setId(resultSet.getLong("sad_so_id"));
      saleOff.setTitle(resultSet.getString("sad_so_title"));
      saleOff.setStartDate(resultSet.getDate("sad_so_start_date"));
      saleOff.setEndDate(resultSet.getDate("sad_so_end_date"));

      scheduleTour.setBusiness(business);
      scheduleTour.setAvatar(sadAvatar);
      scheduleTour.setSaleOff(saleOff);
      return scheduleTour;
   }
}
